package com.longrise.android.loaddata;

import java.io.File;
import java.io.RandomAccessFile;


/**
 * Created by callxkj on 16/5/17.
 *
 */
public class FileWriteUtil{


    /**
     * 把字符串写入文件
     *
     * @param content 需要写入的字符串
     * @param path    文件路径名称
     * @param append  是否以添加的模式写入
     * @return 是否写入成功
     */
    public static boolean writeFile(String content, String path, boolean append) {
        boolean res = false;
        File f = new File(path);
        RandomAccessFile raf = null;
        try {
            if (f.exists()) {
                if (!append) {
                    f.delete();
                    f.createNewFile();
                }
            } else {
                f.createNewFile();
            }
            if (f.canWrite()) {
                raf = new RandomAccessFile(f, "rw");
                raf.seek(raf.length());
                raf.writeBytes(content+"\r\n");
                res = true;
            }
        } catch (Exception e) {

        } finally {

        }
        return res;
    }


}

